package domain.components;

import java.awt.Color;

import com.uqbar.vainilla.DeltaState;
import com.uqbar.vainilla.GameComponent;
import com.uqbar.vainilla.appearances.Circle;
import com.uqbar.vainilla.events.constants.Key;

import domain.scenes.MainGameScene;
import domain.worm.Worm;

public class SightComponent extends GameComponent<MainGameScene> {
	
	private int diameter;
	
	private double movX, movY;
	private Boolean flagXWithD = true;
	private Boolean flagYWithD = true;
	private Boolean flagMoveWithD = true;
	
	private Boolean flagXWithA = false;
	private Boolean flagYWithA = true;
	private Boolean flagMoveWithA = true;
	
	private Worm worm;
	
	public SightComponent(double x, double y, Worm worm){
		super(x,y);
		this.worm = worm;
		this.diameter = 5;
		this.movX = 0;
		this.movY = -1;
		this.setAppearance(new Circle(Color.red, this.diameter));
	}
	
	public int getDiameter(){
		return this.diameter;
	}
	
	public void update(DeltaState deltaState) {
		if(deltaState.isKeyBeingHold(Key.UP)){
			if(this.worm.getDir() == 1){
				if(this.movX> 0){
					this.movX -= 0.1;
				}
				
			}else{
				
			}
		}
		
		if(deltaState.isKeyBeingHold(Key.DOWN)){
			if(this.worm.getDir() == 1){
				
			}
		}
//		if(deltaState.isKeyBeingHold(Key.UP)){
//			this.move(movX, movY);
//
//			if(flagMoveWithD){
//				this.moveSpacecraftInXWithD();
//			}else{
//				this.moveSpacecraftInYWithD();
//			}
//		}
//		
//		if(deltaState.isKeyBeingHold(Key.DOWN)){
//			this.move(movX, movY);
//			if(flagMoveWithA){
//				this.moveSpacecraftInXWithA();
//			}else{
//				this.moveSpacecraftInYWithA();
//			}
//		}
		
}
	
	private void moveSpacecraftInXWithD(){
		if(flagXWithD){
			this.movX += 0.1;
		}else{
			this.movX -= 0.1;
		}
		
		if(this.movX >= 1){
			flagXWithD = false;
			flagMoveWithD = false;//this.moveSpacecraftInY();
		}
		if(this.movX <= -1){
			flagXWithD = true;
			flagMoveWithD = false;
		}
	}
	
	private void moveSpacecraftInYWithD(){
		if(flagYWithD){
			this.movY += 0.1;
		}else{
			this.movY -= 0.1;
		}
		
		if(this.movY >= 1){
			flagYWithD = false;
			flagMoveWithD = true;
		}
		if(this.movY <= -1){
			flagYWithD = true;
			flagMoveWithD = true;
		}
	}
	
	
	private void moveSpacecraftInXWithA(){
		if(flagXWithA){
			this.movX += 0.1;
		}else{
			this.movX -= 0.1;
		}
		
		if(this.movX >= 1){
			flagXWithA = false;
			flagMoveWithA = false;
		}
		if(this.movX <= -1){
			flagXWithA = true;
			flagMoveWithA = false;
		}
	}
	
	private void moveSpacecraftInYWithA(){
		if(flagYWithA){
			this.movY += 0.1;
		}else{
			this.movY -= 0.1;
		}
		
		if(this.movY >= 1){
			flagYWithA = false;
			flagMoveWithA = true;
		}
		if(this.movY <= -1){
			flagYWithA = true;
			flagMoveWithA = true;
		}
	}
	
}
